package com.lin.controller;

import com.lin.annotation.MyLog;
import com.lin.pojo.User;
import com.lin.services.BasicService;
import com.lin.services.UserService;
import com.lin.utils.ShiroUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * ClassName:BasicController
 * Package:com.lin.controller
 * Author: hellcat
 * Date: 2019/12/20
 * ♣♣♣  基本资料
 */
@Controller
@RequestMapping("/basic")
public class BasicController {
    @Autowired
    private BasicService basicService;
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/toBasic", method = RequestMethod.GET)
    public String toBasic(HttpServletRequest request) {
        request.setAttribute("ddId", "Basic");
        User user = userService.getUserByUsername(ShiroUtil.getUser().getAccountNumber());
        request.setAttribute("USER_SESSION", user);
        return "basicMain";
    }

    @RequestMapping(value = "/basicUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateBasic(HttpServletRequest request) {
        String value = request.getParameter("updateValue");
        String object = request.getParameter("updateObject");
        return basicService.updateBasic(object, value);
    }

    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updatePassword(HttpServletRequest request) {
        String oldPwd = request.getParameter("oldPwd");
        String newPwd = request.getParameter("newPwd");
        return basicService.updatePwd(oldPwd, newPwd);
    }

}
